//
//  LookVideo1.m
//  iphoneLive
//
//  Created by Rookie on 2018/7/9.
//  Copyright © 2018年 cat. All rights reserved.
//

#import "LookVideo1.h"


#import <CWStatusBarNotification/CWStatusBarNotification.h>
#import "videoMoreView.h"
#import <SDWebImage/UIImage+GIF.h>
#import "commentview.h"

#import "commectDetails.h"
#import "JPVideoPlayerKit.h"
#import "UIImage+MultiFormat.h"

#import "videoPauseView.h"
#import "jubaoVC.h"

#import "myVideoV.h"
#import "CenterVC.h"

#import "JPLookProgressView.h"
#import "JPBufferView.h"

#import "FrontView.h"

@interface LookVideo1 ()<UIActionSheetDelegate,UITextFieldDelegate,UIScrollViewDelegate,videoPauseDelegate,JPVideoPlayerDelegate>
{
    CWStatusBarNotification *_notification;
    
    UIImageView *currentImageView;
    videoPauseView *pasueView;
    
    UIView *_toolBar;
    
    CGFloat lastContenOffset;
}

@property(nonatomic,assign)BOOL isdelete;//
@property(nonatomic,copy)NSString *playUrl;                          //视频播放url
@property(nonatomic,copy)NSString *videoid;                          //视频id
@property(nonatomic,copy)NSString *hostid;                           //主播id
@property(nonatomic,copy)NSString *hosticon;                         //主播头像
@property(nonatomic,copy)NSString *hostname;
@property(nonatomic,copy)NSString *islike;                           //是否点赞
@property(nonatomic,copy)NSString *comments;                         //评论总数
@property(nonatomic,copy)NSString *likes;                            //点赞数
@property(nonatomic,copy)NSString *video_title;                      //视频标题
@property(nonatomic,copy)NSString *shares;                           //分享次数
//@property(nonatomic,copy)NSString *steps;                          //是否踩


@property(nonatomic,strong)videoMoreView *videomore;                //分享view


@property(nonatomic,strong)UIButton *goBackBtn;
@property(nonatomic,strong)UIButton *goBackShadow;

@property(nonatomic,strong)commentview *comment;                    //评论
@property(nonatomic,strong)MyTextField *textField;
@property(nonatomic,strong)UIButton *finishbtn;
@property(nonatomic,strong)NSMutableArray *imgArr;
@property(nonatomic,assign)BOOL isHome;                            //首页-推荐

//播放器---
@property (strong, nonatomic)  UIScrollView *backScrollView;
@property (nonatomic, strong) UIImageView *firstImageView;
@property(nonatomic,strong) FrontView *firstFront;
@property (nonatomic, strong) UIImageView *secondImageView;
@property(nonatomic,strong) FrontView *secondFront;
@property (nonatomic, strong) UIImageView *thirdImageView;
@property(nonatomic,strong) FrontView *thirdFront;
@property(nonatomic, assign) CGFloat scrollViewOffsetYOnStartDrag;

@property (nonatomic, strong) NSArray<NSString *> *douyinVideoStrings;
@property(nonatomic, assign) NSUInteger currentVideoIndex;



@end

@implementation LookVideo

-(void)clickLeftBtn {
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [IQKeyboardManager sharedManager].enable = YES;
    
    [self.secondImageView jp_pause];
    [self hideAnimation];
    [self.secondFront.symbolBIV.layer removeAllAnimations];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [IQKeyboardManager sharedManager].enable = NO;
    [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
    //self.navigationController.navigationBarHidden = YES;
    [self startAllAnimation];
}
#pragma mark - 动画的控制
-(void)hideAnimation {
    self.firstFront.symbolAIV.hidden = YES;
    self.firstFront.symbolBIV.hidden = YES;
    self.secondFront.symbolAIV.hidden = YES;
    self.secondFront.symbolBIV.hidden = YES;
    self.thirdFront.symbolAIV.hidden = YES;
    self.thirdFront.symbolBIV.hidden = YES;
}
-(void)startAllAnimation {
    [self pubAnimation:self.secondFront];
    [self pubAnimation:self.firstFront];
    [self pubAnimation:self.thirdFront];
    
}
-(void)pubAnimation:(FrontView*)front{
    front.symbolAIV.hidden = NO;
    [front.discIV.layer addAnimation:[PublicObj rotationAnimation] forKey:@"rotation"];
    [front.symbolAIV.layer addAnimation:[PublicObj caGroup] forKey:@"group"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        front.symbolBIV.hidden = NO;
        [front.symbolBIV.layer addAnimation:[PublicObj caGroup] forKey:@"group1"];
    });
}



- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
//    if (wmPlayer) {
//        [wmPlayer play];
//
//        [self getVideo];
//    }
    [self.secondImageView jp_resume];
    
    if (pasueView) {
        pasueView.hidden = YES;
    }
}
-(void)dealloc{
//    [self releaseWMPlayer];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //在回复页面回复了之后，在本页面需要增加评论数量
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloaComments:) name:@"allComments" object:nil];
    //回复之后刷新数据
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getnewreload) name:@"reloadcomments" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:)name:UIKeyboardWillHideNotification object:nil];
    lastContenOffset = 0;
    //滚动视图
    [self.view insertSubview:self.backScrollView atIndex:5];
    
    //加到_pageView上效果不大好
    UIImageView *mask_top = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100+statusbarHeight)];
    [mask_top setImage:[UIImage imageNamed:@"home_mask_top"]];//video_record_mask_top//home_mask_top
    [self.view addSubview:mask_top];
    
    UIImageView* mask_buttom = [[UIImageView alloc] initWithFrame:CGRectMake(0,  _window_height- 100, self.view.frame.size.width, 100)];
    [mask_buttom setImage:[UIImage imageNamed:@"home_mask_bottom"]];
    [self.view addSubview:mask_buttom];
    
    UITapGestureRecognizer *tapone = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doPauseView)];
    tapone.numberOfTapsRequired = 1;
    [_backScrollView addGestureRecognizer:tapone];
    
    _imgArr = [NSMutableArray array];
    CGFloat X = 0;
    for (int i=0; i<_videoList.count; i++) {
        UIImageView *imagevB = [[UIImageView alloc]initWithFrame:CGRectMake(0, X, _window_width, _window_height)];
        imagevB.userInteractionEnabled = YES;
        imagevB.backgroundColor = [UIColor blackColor];
        imagevB.contentMode = UIViewContentModeScaleAspectFill;
        imagevB.clipsToBounds = YES;
//        [_backScrollView addSubview:imagevB];
        if (i == _curentIndex) {
            currentImageView = imagevB;
            currentImageView.hidden = YES;
//            wmPlayer.placeholderImage = _firstPlaceImage;
            [imagevB sd_setImageWithURL:[NSURL URLWithString:[_videoList[i] valueForKey:@"thumb"]]];
        }
        [_imgArr addObject:imagevB];
        X+=_window_height;
    }
    
//    //布局：右边组合
//    [self.view addSubview:self.rightView];
//    //布局：底部组合
//    [self.view addSubview:self.botView];
    
    /**
     * 判断来源 videoList 不为空判定为其他页面跳转至此,否则即为首页初次加载(视为首页-推荐)
     */
    if (!_videoList || _videoList.count == 0) {
        _isHome = YES;
        _curentIndex = 0;
        _pages = 1;
        self.videoList = [NSMutableArray array];
        [self requestMoreVideo];
    }else{
//        [self releaseWMPlayer];
//        [self createWmplayer];
        
        _currentVideoIndex = 0;
        _scrollViewOffsetYOnStartDrag = -100;
        [self scrollViewDidEndScrolling];
        
        [self setData];
        [self getVideo];//视频详情
    }
    
    UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(messgaebtn:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
//    [wmPlayer addGestureRecognizer:recognizer];
    
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryPlayback  error:nil];
    
    //向左滑动进入个人主页
    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(zhuboMessage)];
    swipe.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:swipe];
    
    if (_curentIndex>=_videoList.count-2) {
        _pages += 1;
        [self requestMoreVideo];
    }
    
    if (_fromWhere) {
        [self.view addSubview:self.goBackBtn];
        [self showtextfield];
    }
    
   
    
}


#pragma mark - scrollView delegate

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    lastContenOffset = scrollView.contentOffset.y;
    
    self.secondImageView.jp_progressView.hidden = YES;
    self.scrollViewOffsetYOnStartDrag = scrollView.contentOffset.y;
}

-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
    
    
    
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
   
    NSLog(@"currentIndex=====%.2f",scrollView.contentSize.height);
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    
    if (lastContenOffset < scrollView.contentOffset.y && (scrollView.contentOffset.y-lastContenOffset)>=_window_height) {
        NSLog(@"=====向上滚动=====");
        _curentIndex+1 == _imgArr.count ? [YBMsgPop showPop:@"没有更多了哦^_^"]:@"";
        _curentIndex++;
    }else if(lastContenOffset > scrollView.contentOffset.y && (lastContenOffset-scrollView.contentOffset.y)>=_window_height){
        _curentIndex <= 0 ? [YBMsgPop showPop:@"已经到顶了哦^_^"]:@"";
        NSLog(@"=====向下滚动=====");
        _curentIndex--;
        if (_curentIndex<0) {
            _curentIndex=0;
        }
    }else{
        NSLog(@"=======本页拖动为改变数据=======");
    }
    
    
    self.secondImageView.jp_progressView.hidden = NO;
    [self scrollViewDidEndScrolling];
    
    if (_requestUrl) {
        if (_curentIndex>=_videoList.count-2) {
            _pages += 1;
            [self requestMoreVideo];
        }
    }
    
}
#pragma mark - Private

- (void)scrollViewDidEndScrolling {
    
    if(self.scrollViewOffsetYOnStartDrag == self.backScrollView.contentOffset.y){
        return;
    }
    NSLog(@"7-8==%f====%f",self.scrollViewOffsetYOnStartDrag,self.backScrollView.contentOffset.y);
    [self changeRoom];
    
}
#pragma mark - 切换房间
-(void)changeRoom{
    
    [self changeCurrentImageView];
    if (_videomore) {
        [_videomore removeFromSuperview];
        _videomore = nil;
    }
    
    if (pasueView) {
        [pasueView removeFromSuperview];
        pasueView = nil;
    }
    
    _hostdic = [NSDictionary dictionary];
    _hostdic = _videoList[_curentIndex];
    _playUrl = [NSString stringWithFormat:@"%@",[_hostdic valueForKey:@"href"]];
    [self setData];
    
    [self.backScrollView setContentOffset:CGPointMake(0, _window_height) animated:NO];
    [self.secondImageView jp_stopPlay];
    [self.secondImageView jp_playVideoMuteWithURL:[NSURL URLWithString:_playUrl]
                               bufferingIndicator:[JPBufferView new]
                                     progressView:[JPLookProgressView new]
                                    configuration:^(UIView *view, JPVideoPlayerModel *playerModel) {
                                        view.jp_muted = NO;
                                        if (self.secondImageView.image.size.width>0 && (self.secondImageView.image.size.width >= self.secondImageView.image.size.height)) {
                                            playerModel.playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
                                        }else{
                                            playerModel.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
                                        }
                                    }];
    
    [self getVideo];
    
}
- (void)changeCurrentImageView{
    for (int i = 0; i<_videoList.count; i++) {
       
        if (i==_curentIndex-1) {
             [_firstImageView sd_setImageWithURL:[NSURL URLWithString:minstr([_videoList[i] valueForKey:@"thumb"])]];
        }
        if (i==_curentIndex) {
            [_secondImageView sd_setImageWithURL:[NSURL URLWithString:minstr([_videoList[i] valueForKey:@"thumb"])]];
        }
        if (i==_curentIndex+1) {
            [_thirdImageView sd_setImageWithURL:[NSURL URLWithString:minstr([_videoList[i] valueForKey:@"thumb"])]];
            
        }
        
    }
}


#pragma mark - 通知
-(void)reloaComments:(NSNotification *)ns{
    NSDictionary *subdic = [ns userInfo];
    [_secondFront.commentBtn setTitle:[NSString stringWithFormat:@"%@",[subdic valueForKey:@"allComments"]] forState:0];
    if (_comment) {
        [_comment getNewCount:[[subdic valueForKey:@"allComments"] intValue]];
    }
}
-(void)getnewreload{
    //获取视频信息
    id userinfo = [_hostdic valueForKey:@"userinfo"];
    if ([userinfo isKindOfClass:[NSDictionary class]]) {
        _hostid = [NSString stringWithFormat:@"%@",[userinfo valueForKey:@"id"]];
        _hosticon = [NSString stringWithFormat:@"%@",[userinfo valueForKey:@"avatar"]];
        _hostname = [NSString stringWithFormat:@"%@",[userinfo valueForKey:@"user_nicename"]];
    }else{
        _hostid = @"0";
        _hosticon = @"";
        _hostname = @"";
    }
    
    //NSDictionary *userinfo = [_hostdic valueForKey:@"userinfo"];
    //_hostid = [NSString stringWithFormat:@"%@",[userinfo valueForKey:@"id"]];
    //_hosticon = [NSString stringWithFormat:@"%@",[userinfo valueForKey:@"avatar"]];
    //_hostname = [NSString stringWithFormat:@"%@",[userinfo valueForKey:@"user_nicename"]];
    
    _videoid = [NSString stringWithFormat:@"%@",[_hostdic valueForKey:@"id"]];
    _likes = [NSString stringWithFormat:@"%@",[_hostdic valueForKey:@"likes"]];
    _islike = [NSString stringWithFormat:@"%@",[_hostdic valueForKey:@"islike"]];
}

#pragma  mark - 视频详情
-(void)getVideo{
    NSString *url = [purl stringByAppendingFormat:@"?service=Video.getVideo"];
    NSDictionary *subdic = @{
                             @"uid":[Config getOwnID],
                             @"videoid":[NSString stringWithFormat:@"%@",[_hostdic valueForKey:@"id"]]
                             };;
    WeakSelf;
    [YBNetworking postWithUrl:url Dic:subdic Suc:^(NSDictionary *data, NSString *code, NSString *msg) {
        if([code isEqual:@"0"]) {
            NSDictionary *info = [[data valueForKey:@"info"] firstObject];
            weakSelf.shares =[NSString stringWithFormat:@"%@",[info valueForKey:@"shares"]];
            weakSelf.likes = [NSString stringWithFormat:@"%@",[info valueForKey:@"likes"]];
            weakSelf.islike = [NSString stringWithFormat:@"%@",[info valueForKey:@"islike"]];
            weakSelf.comments = [NSString stringWithFormat:@"%@",[info valueForKey:@"comments"]];
            //_steps = [NSString stringWithFormat:@"%@",[info valueForKey:@"steps"]];
            
            dispatch_async(dispatch_get_main_queue(), ^{
                //点赞数 评论数 分享数
                if ([weakSelf.islike isEqual:@"1"]) {
                    [weakSelf.secondFront.likebtn setImage:[UIImage imageNamed:@"home_zan_sel"] forState:0];
                    //weakSelf.likebtn.userInteractionEnabled = NO;
                } else{
                    [weakSelf.secondFront.likebtn setImage:[UIImage imageNamed:@"home_zan"] forState:0];
                    //weakSelf.likebtn.userInteractionEnabled = YES;
                }
                [weakSelf.secondFront.likebtn setTitle:[NSString stringWithFormat:@"%@",weakSelf.likes] forState:0];
                [weakSelf.secondFront.enjoyBtn setTitle:[NSString stringWithFormat:@"%@",weakSelf.shares] forState:0];
                [weakSelf.secondFront.commentBtn setTitle:[NSString stringWithFormat:@"%@",weakSelf.comments] forState:0];
                NSString *isattent = [NSString stringWithFormat:@"%@",[NSString stringWithFormat:@"%@",[info valueForKey:@"isattent"]]];
                if ([[Config getOwnID] isEqual:weakSelf.hostid]) {
                    weakSelf.secondFront.followBtn.hidden = YES;
                }else if ([isattent isEqual:@"1"]) {
                    //[_followBtn setImage:[UIImage imageNamed:@"home_follow_sel"] forState:0];
                    weakSelf.secondFront.followBtn.hidden = YES;
                }else{
                    [weakSelf.secondFront.followBtn setImage:[UIImage imageNamed:@"home_follow"] forState:0];
                    weakSelf.secondFront.followBtn.hidden = NO;
                }
            });
        }else if ([code isEqual:@"700"]) {
            [PublicObj tokenExpired:[data valueForKey:@"msg"]];
        }else{
            [HUDHelper myalert:[data valueForKey:@"msg"]];
            //dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            //  [self canclebtn:nil];
            //});
        }
    } Fail:nil];
    
}
-(void)setData{
    //列表上的信息会存在刷新不及时，需要请求接口刷新Video.getVideo
    //获取视频间信息
    
    id userinfo = [_hostdic valueForKey:@"userinfo"];
    if ([userinfo isKindOfClass:[NSDictionary class]]) {
        _hostid = [NSString stringWithFormat:@"%@",[userinfo valueForKey:@"id"]];
        _hosticon = [NSString stringWithFormat:@"%@",[userinfo valueForKey:@"avatar"]];
        _hostname = [NSString stringWithFormat:@"@%@",[userinfo valueForKey:@"user_nicename"]];
    }else{
        _hostid = @"0";
        _hosticon = @"";
        _hostname = @"";
    }
    
    _videoid = [NSString stringWithFormat:@"%@",[_hostdic valueForKey:@"id"]];
    _video_title = [NSString stringWithFormat:@"%@",[_hostdic valueForKey:@"title"]];
    _secondFront.titleL.text = _video_title;
    _secondFront.nameL.text = _hostname;
    [_secondFront.iconBtn sd_setBackgroundImageWithURL:[NSURL URLWithString:_hosticon] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"default_head.png"]];
    
    //计算名称长度
    CGSize titleSize = [_secondFront.titleL.text boundingRectWithSize:CGSizeMake(_window_width*0.75, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:SYS_Font(20)} context:nil].size;
    _secondFront.titleL.frame = CGRectMake(0, _secondFront.musicL.top-titleSize.height, titleSize.width, titleSize.height);
    _secondFront.nameL.frame = CGRectMake(0, _secondFront.titleL.top-25, _secondFront.botView.width, 25);
    _secondFront.followBtn.frame = CGRectMake(_secondFront.iconBtn.left+12, _secondFront.iconBtn.bottom-13, 26, 26);
    if ([[Config getOwnID] isEqual:_hostid]) {
        _secondFront.followBtn.hidden = YES;
    }else{
        _secondFront.followBtn.hidden = NO;
    }
    
//    NSInteger first_index,second_index,third_index;
//    first_index = (_curentIndex-1 > 0) ? (_curentIndex-1):0;
//    second_index = _curentIndex;
//    third_index = _curentIndex+1;
//    _firstImageView.image = _imgArr[first_index];
    
    
    
}

//评论
-(void)showtextfield{
    
    if (!_toolBar) {
        _toolBar = [[UIView alloc]initWithFrame:CGRectMake(0,_window_height - 50, _window_width, 50)];
        _toolBar.backgroundColor = RGB_A(32, 28, 54, 0.2);//RGB(27, 25, 41);;//RGB(248, 248, 248);
        [self.view addSubview:_toolBar];
        
        //设置输入框
        UIView *vc  = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
        vc.backgroundColor = [UIColor clearColor];
        _textField = [[MyTextField alloc]initWithFrame:CGRectMake(10,8, _window_width - 100, 34)];
        _textField.backgroundColor = RGB_A(44, 40, 64, 0.2);//RGB(34, 33, 49);//[UIColor whiteColor];
        _textField.layer.masksToBounds = YES;
        _textField.layer.cornerRadius = 17;
        //_textField.layer.borderColor = RGB_A(44, 40, 64, 1).CGColor;//[UIColor groupTableViewBackgroundColor].CGColor;
        //_textField.layer.borderWidth = 1.0;
        _textField.placeholder = @" 说点什么吧~";
        _textField.textColor = RGB(150, 150, 150);
        _textField.placeCol = RGB(150, 150, 150);
        _textField.delegate = self;
        _textField.returnKeyType = UIReturnKeyDone;
        [_toolBar addSubview:_textField];
        _textField.leftViewMode = UITextFieldViewModeAlways;
        _textField.leftView = vc;
        [_textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        
        _finishbtn = [UIButton buttonWithType:0];
        _finishbtn.frame = CGRectMake(_window_width - 80,8,70,34);
        [_finishbtn setImage:[UIImage imageNamed:@"发送按钮_无文字"] forState:0];
        [_finishbtn addTarget:self action:@selector(pushmessage) forControlEvents:UIControlEventTouchUpInside];
        [_toolBar addSubview:_finishbtn];
    }
    //[textField becomeFirstResponder];
}
//监听textfield
-(void)textFieldDidChange :(UITextField *)theTextField{
    NSLog( @"text changed: %@", theTextField.text);
    if (theTextField.text.length == 0) {
        [_finishbtn setImage:[UIImage imageNamed:@"发送按钮_无文字"] forState:0];
    }
    else{
        [_finishbtn setImage:[UIImage imageNamed:@"发送按钮_有文字"] forState:0];
    }
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self pushmessage];
    return YES;
}
#pragma mark -- 获取键盘高度
- (void)keyboardWillShow:(NSNotification *)aNotification {
    //获取键盘的高度
    NSDictionary *userInfo = [aNotification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    CGFloat height = keyboardRect.origin.y;
    _toolBar.frame = CGRectMake(0, height - 50, _window_width, 50);
}
- (void)keyboardWillHide:(NSNotification *)aNotification {
    [UIView animateWithDuration:0.1 animations:^{
        _toolBar.frame = CGRectMake(0, _window_height - 50-statusbarHeight, _window_width, 50+statusbarHeight);
        //_toolBar.frame = CGRectMake(0, _window_height + 10, _window_width, 50);
    }];
}

//点击关注主播
-(void)guanzhuzhubo{
    if ([[Config getOwnID] intValue]<0) {
        [PublicObj warnLogin];
        return;
    }
    NSString *url = [purl stringByAppendingFormat:@"?service=User.setAttent"];
    NSDictionary *subdic = @{
                             @"uid":[Config getOwnID],
                             @"touid":_hostid
                             };
    WeakSelf;
    [YBNetworking postWithUrl:url Dic:subdic Suc:^(NSDictionary *data, NSString *code, NSString *msg) {
        if([code isEqual:@"0"]) {
            
            [weakSelf.secondFront.followBtn setImage:[UIImage imageNamed:@"home_follow_sel"] forState:0];
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.secondFront.followBtn.imageView.layer addAnimation:[PublicObj smallToBigToSmall] forKey:nil];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.9 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    weakSelf.secondFront.followBtn.frame = CGRectMake(weakSelf.secondFront.iconBtn.left+12, weakSelf.secondFront.iconBtn.bottom-13, 0, 0);
                    [weakSelf.secondFront.followBtn setImage:[UIImage imageNamed:@"home_follow"] forState:0];
                });
            });
            /*
             [UIView animateWithDuration:1 animations:^{
             weakSelf.followBtn.transform = CGAffineTransformMakeScale(1.3, 1.3);
             weakSelf.followBtn.transform = CGAffineTransformMakeScale(0.01, 0.01);
             } completion:^(BOOL finished) {
             weakSelf.followBtn.frame = CGRectMake(weakSelf.iconBtn.left+12, weakSelf.iconBtn.bottom-13, 0, 0);
             weakSelf.followBtn.transform = CGAffineTransformMakeScale(1, 1);
             }];
             */
            
        }else if ([code isEqual:@"700"]) {
            [PublicObj tokenExpired:[data valueForKey:@"msg"]];
        }else{
            [HUDHelper myalert:[data valueForKey:@"msg"]];
        }
    } Fail:nil];
    
}
-(void)zhuboMessage{
    
    //    if ([[Config getOwnID] intValue]<=0) {
    //        [PublicObj warnLogin];
    //        return;
    //    }
    
    CenterVC *center = [[CenterVC alloc]init];
    center.isOther = YES;
    center.otherUid =_hostid;
    center.hidesBottomBarWhenPushed = YES;
//    if (wmPlayer) {
//        [wmPlayer pause];
//    }
    [self.navigationController pushViewController:center animated:YES];
    
}
-(void)doPauseView{
    
    if (_toolBar && _toolBar.y<_window_height-50) {
        [_textField resignFirstResponder];
        return;
    }
    
    [_textField resignFirstResponder];
    
    if (!pasueView) {
        CGFloat hhhhhhh;
        if ([minstr([_hostdic valueForKey:@"is_urge"]) intValue] != 1 || [minstr([[_hostdic valueForKey:@"userinfo"] valueForKey:@"id"]) isEqual:[Config getOwnID]]) {
            hhhhhhh = _window_width*0.8;
        }else{
            hhhhhhh = _window_width;
        }
        pasueView = [[videoPauseView alloc]initWithFrame:CGRectMake(0, (_window_height-hhhhhhh)/2+_window_height, _window_width, hhhhhhh) andVideoMsg:_hostdic];
        pasueView.delegate = self;
        [_backScrollView addSubview:pasueView];
        
    }else{
        pasueView.hidden = NO;
    }
    pasueView.fromWhere = _fromWhere;
    [pasueView requestNewVideoMsgAndIslike:_islike];
    //[wmPlayer pause];
    
    [self.secondImageView jp_pause];
    
}
#pragma mark ================ pasueViewDelegate ===============
- (void)goPlay{
    if (pasueView) {
        pasueView.hidden = YES;
    }
    [self.secondImageView jp_resume];
//    [wmPlayer play];
//    wmPlayer.placeholderImage = nil;
    currentImageView.hidden = YES;
}
-(void)chongxinbofang{
    if (pasueView) {
        pasueView.hidden = YES;
    }
//    [self releaseWMPlayer];
//    [self createWmplayer];
}
- (void)quzhuyelelelel{
    
    if ([[Config getOwnID] intValue]<=0) {
        [PublicObj warnLogin];
        return;
    }
    
    [self zhuboMessage];
}
- (void)isdianzan:(NSString *)islike andlikes:(NSString *)likes{
    if (islike == nil && likes == nil) {
        [PublicObj warnLogin];
        return;
    }
    _islike = islike;
    [_secondFront.likebtn setTitle:[NSString stringWithFormat:@"%@",likes] forState:0];
    if ([islike isEqual:@"1"]) {
        [_secondFront.likebtn setImage:[UIImage imageNamed:@"home_zan_sel"] forState:0];
    }
    else{
        [_secondFront.likebtn setImage:[UIImage imageNamed:@"home_zan"] forState:0];
    }
}
- (void)addShareNums:(NSString *)shareNum{
    [_secondFront.enjoyBtn setTitle:[NSString stringWithFormat:@"%@",shareNum] forState:0];
}


- (void)canclebtn:(id)sender {
    
    if (self.block && _videoList.count > 1) {
        self.block(_videoList, _pages, _curentIndex);
    }
//    [self releaseWMPlayer];
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
//分享
-(void)doenjoy{
    [self morebtn:nil];
}
-(void)morebtn:(id)sender {
    //    if ([[Config getOwnID] intValue]<0) {
    //        [PublicObj warnLogin];
    //        return;
    //    }
    if (!_videomore) {
        WeakSelf;
        NSArray *array = [common share_type];
        CGFloat hh = _window_height/3+50;
        if (array.count == 0) {
            hh = _window_height/3/2+50;
        }
        _videomore = [[videoMoreView alloc]initWithFrame:CGRectMake(0, _window_height+20, _window_width, hh) andHostDic:_hostdic cancleblock:^(id array) {
            [weakSelf hideMoreView];
        } delete:^(id array) {
            [weakSelf canclebtn:nil];
        } share:^(id array) {
            weakSelf.shares = array;
            [weakSelf.secondFront.enjoyBtn setTitle:[NSString stringWithFormat:@"%@",weakSelf.shares] forState:0];
        }];
        _videomore.fromWhere = _fromWhere;
        _videomore.jubaoBlock = ^(id array) {
            jubaoVC *jubao = [[jubaoVC alloc]init];
            jubao.dongtaiId = array;
            jubao.type = @"0";//举报视频
            jubao.fromWhere = weakSelf.fromWhere ? weakSelf.fromWhere:@"LookVideo";
            [weakSelf presentViewController:jubao animated:YES completion:nil];
        };
        
        [weakSelf.view addSubview:_videomore];
        
        
        _videomore.hidden = YES;
    }
    _videomore.fromWhere = _fromWhere;
    
    if (_videomore.hidden == YES) {
        [self showMoreView];
    }else{
        [self hideMoreView];
    }
}
-(void)showMoreView{
    
    self.tabBarController.tabBar.hidden = YES;
    WeakSelf;
    [UIView animateWithDuration:0.5 animations:^{
        weakSelf.videomore.frame = CGRectMake(0, _window_height - _window_height/3-50, _window_width, _window_height/3+50);
        NSArray *array = [common share_type];
        //如果没有分享
        if (array.count == 0) {
            weakSelf.videomore.frame = CGRectMake(0, _window_height - _window_height/3/2-50, _window_width, _window_height/3/2+50);
        }
        weakSelf.videomore.hidden = NO;
    }];
}
-(void)hideMoreView{
    
    self.tabBarController.tabBar.hidden = NO;
    WeakSelf;
    [UIView animateWithDuration:0.5 animations:^{
        weakSelf.videomore.frame = CGRectMake(0, _window_height +20, _window_width, _window_height/2.2);
        NSArray *array = [common share_type];
        if (array.count == 0) {
            weakSelf.videomore.frame = CGRectMake(0, _window_height +20, _window_width, _window_height/2.2/2);
        }
        weakSelf.videomore.hidden = YES;
    }];
}
//点赞
-(void)dolike{
    if ([[Config getOwnID] intValue]<0) {
        [PublicObj warnLogin];
        return;
    }
    //可以取消-注释掉
    /*
     if ([_islike isEqual:@"1"]){
     return;
     }
     */
    
    NSString *url = [purl stringByAppendingFormat:@"/?service=Dialect.likeIspay"];
    NSDictionary *parameterDic = @{
                                   @"uid":[Config getOwnID],
                                   @"token":[Config getOwnToken]
                                   };
    [YBNetworking postWithUrl:url Dic:parameterDic Suc:^(NSDictionary *data, NSString *code, NSString *msg) {
        if([code isEqual:@"0"]) {
            NSDictionary *info = [data valueForKey:@"info"];
            
            if ([minstr([info valueForKey:@"isfree"]) isEqual:@"0"]) {
                [self checkLiveSuc:@"0"];
            }else{
                [self checkLiveSuc:@"0"];
                /*
                 UIAlertController *alertContro = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"免费点赞已用完，继续点赞需花费%@%@",minstr([info valueForKey:@"likemoney"]),[common name_coin]]  preferredStyle:UIAlertControllerStyleAlert];
                 UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                 }];
                 [alertContro addAction:cancleAction];
                 UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                 [weakself checkLiveSuc:@"1"];
                 }];
                 [alertContro addAction:sureAction];
                 [self presentViewController:alertContro animated:YES completion:nil];
                 */
            }
        }else if ([code isEqual:@"700"]) {
            [PublicObj tokenExpired:[data valueForKey:@"msg"]];
        }
    } Fail:nil];
    
}
- (void)checkLiveSuc:(NSString *)isFull{
    NSString *url = [purl stringByAppendingFormat:@"?service=Video.addLike&uid=%@&videoid=%@&type=%@",[Config getOwnID],_videoid,isFull];
    WeakSelf;
    [YBNetworking postWithUrl:url Dic:nil Suc:^(NSDictionary *data, NSString *code, NSString *msg) {
        if([code isEqual:@"0"]) {
            NSDictionary *info = [[data valueForKey:@"info"] firstObject];
            weakSelf.islike = [NSString stringWithFormat:@"%@",[info valueForKey:@"islike"]];
            weakSelf.likes  = [NSString stringWithFormat:@"%@",[info valueForKey:@"likes"]];
            [weakSelf.secondFront.likebtn setTitle:[NSString stringWithFormat:@"%@",weakSelf.likes] forState:0];
            if ([weakSelf.islike isEqual:@"1"]) {
                //先将图片置空->放动图(重新set从第一帧开始)->动图消失放静态图
                //放一张透明占位图
                [weakSelf.secondFront.likebtn setImage:[UIImage imageNamed:@"home_zan_space"] forState:0];
                weakSelf.secondFront.likeGifIV.hidden = NO;
                [weakSelf.secondFront.likeGifIV setImage:weakSelf.secondFront.likeSelGif];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.49 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    weakSelf.secondFront.likeGifIV.hidden = YES;
                    [weakSelf.secondFront.likeGifIV setImage:[UIImage imageNamed:@""]];
                    [weakSelf.secondFront.likebtn setImage:[UIImage imageNamed:@"home_zan_sel"] forState:0];
                });
                //weakSelf.likebtn.userInteractionEnabled = NO;
                //[weakself starlight];
            }else{
                [weakSelf.secondFront.likebtn setImage:[UIImage imageNamed:@"home_zan"] forState:0];
                weakSelf.secondFront.likeGifIV.hidden = NO;
                [weakSelf.secondFront.likeGifIV setImage:weakSelf.secondFront.likeCacelGif];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.26 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    weakSelf.secondFront.likeGifIV.hidden = YES;
                    [weakSelf.secondFront.likeGifIV setImage:[UIImage imageNamed:@""]];
                });
                //weakSelf.likebtn.userInteractionEnabled = YES;
            }
        }else if ([code isEqual:@"700"]) {
            [PublicObj tokenExpired:[data valueForKey:@"msg"]];
        }
    } Fail:nil];
    
}
//评论列表
- (void)messgaebtn:(id)sender {
    
    if ([[Config getOwnID] intValue]<=0) {
        [PublicObj warnLogin];
        return;
    }
    
    if (_comment) {
        [_comment removeFromSuperview];
        _comment = nil;
    }
    
    WeakSelf;
    if (!_comment) {
        _comment = [[commentview alloc]initWithFrame:CGRectMake(0,_window_height, _window_width, _window_height) hide:^(NSString *type) {
            [UIView animateWithDuration:0.3 animations:^{
                weakSelf.comment.frame = CGRectMake(0, _window_height, _window_width, _window_height);
                //显示tabbar
                self.tabBarController.tabBar.hidden = NO;
            } ];
        } andvideoid:_videoid andhostid:_hostid count:[_comments intValue] talkCount:^(id type) {
            //刷新评论数显示
            [weakSelf.secondFront.commentBtn setTitle:[NSString stringWithFormat:@"%@",type] forState:0];
            weakSelf.comments = type;
        } detail:^(id type) {
            [weakSelf pushdetails:type];
        } youke:^(id type) {
            [PublicObj warnLogin];
        } andFrom:_fromWhere];
        
        //[self.view addSubview:comment];
        
        if (_fromWhere) {
            //从其他页面push过来 没self.tabBarController
            [self.view addSubview:_comment];
        }else{
            //一定加在self.tabBarController.view或者  window上
            [self.tabBarController.view addSubview:_comment];
        }
    }
    
    _comment.fromWhere = _fromWhere;
    [_comment getNewCount:[_comments intValue]];
    [UIView animateWithDuration:0.3 animations:^{
        weakSelf.comment.frame = CGRectMake(0,0,_window_width, _window_height);
        //隐藏tabbar
        self.tabBarController.tabBar.hidden = YES;
    }];
}
-(void)pushdetails:(NSDictionary *)type{
    WeakSelf;
    [_comment endEditing:YES];
    _comment.hidden = YES;
    commectDetails *detail = [[commectDetails alloc]init];
    detail.hostDic = type;
    detail.event = ^{
        weakSelf.comment.hidden = NO;
    };
//    if (wmPlayer) {
//        [wmPlayer pause];
//    }
    [self.navigationController pushViewController:detail animated:YES];
}
-(void)pushmessage{
    if ([[Config getOwnID] intValue] < 0) {
        [_textField resignFirstResponder];
        [PublicObj warnLogin];
        return;
    }
    /*
     parentid  回复的评论ID
     commentid 回复的评论commentid
     touid     回复的评论UID
     如果只是评论 这三个传0
     */
    if (_textField.text.length == 0) {
        [HUDHelper myalert:@"请添加内容后再尝试"];
        return;
    }
    NSString *path = _textField.text;
    NSString *url = [purl stringByAppendingFormat:@"/?service=Video.setComment&videoid=%@&content=%@&uid=%@&token=%@&touid=%@&commentid=%@&parentid=%@",_videoid,path,[Config getOwnID],[Config getOwnToken],_hostid,@"0",@"0"];
    //url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    WeakSelf;
    [YBNetworking postWithUrl:url Dic:nil Suc:^(NSDictionary *data, NSString *code, NSString *msg) {
        if([code isEqual:@"0"]){
            //更新评论数量
            NSDictionary *info = [[data valueForKey:@"info"] firstObject];
            NSString *newComments = [NSString stringWithFormat:@"%@",[info valueForKey:@"comments"]];
            weakSelf.comments = newComments;
            [weakSelf.secondFront.commentBtn setTitle:[NSString stringWithFormat:@"%@",newComments] forState:0];
            if (weakSelf.comment) {
                [weakSelf.comment getNewCount:[newComments intValue]];
            }
            /*
             NSString *t2u = [NSString stringWithFormat:@"%@",[info valueForKey:@"t2u"]];//对方是否拉黑我
             NSString *isattent = [NSString stringWithFormat:@"%@",[info valueForKey:@"isattent"]];//对方是否关注我
             
             if ([t2u isEqual:@"0"]) {
             */
            [YBMsgPop showPop:minstr([data valueForKey:@"msg"])];
            weakSelf.textField.text = @"";
            weakSelf.textField.placeholder = @" 说点什么...";
            [weakSelf.finishbtn setImage:[UIImage imageNamed:@"发送按钮_无文字"] forState:0];
            [self.view endEditing:YES];
            /*
             //发送私信
             if (![_hostid isEqual:[Config getOwnID]]) {
             NSString *sixincontent = [NSString stringWithFormat:@"评论:%@",path];
             
             NSDictionary *iconDic = [NSDictionary dictionaryWithObject:isattent forKey:@"isfollow"];
             EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithText:sixincontent];
             
             EMMessage *message = [[EMMessage alloc] initWithConversationID:_hostid from:[Config getOwnID] to:_hostid body:body ext:iconDic];
             
             message.chatType = EMChatTypeChat;// 设置为单聊消息
             message.direction = EMMessageDirectionSend;//方向
             [[EMClient sharedClient].chatManager sendMessage:message progress:nil completion:^(EMMessage *message, EMError *error) {
             NSLog(@"----+++发送成功---%@",error.errorDescription);
             }];
             }
             
             }else{
             [HUDHelper myalert:@"对方暂时拒绝接收您的消息"];
             textField.text = @"";
             textField.placeholder = @" 说点什么...";
             //论完后 把状态清零
             [self.view endEditing:YES];
             }
             */
        }else if ([code isEqual:@"700"]) {
            [PublicObj tokenExpired:[data valueForKey:@"msg"]];
        }else{
            [YBMsgPop showPop:minstr([data valueForKey:@"msg"])];
            weakSelf.textField.text = @"";
            weakSelf.textField.placeholder = @" 说点什么...";
            [self.view endEditing:YES];
        }
    } Fail:nil];
    
}




#pragma mark ================ 请求分页 ===============
- (void)requestMoreVideo {
    NSString *url = [NSString stringWithFormat:@"%@&p=%@",_requestUrl,@(_pages)];
    WeakSelf;
    __block UIImageView *weakCurrentImgV = currentImageView;
//    __block WMPlayer *weakPlayer = wmPlayer;
    [YBNetworking postWithUrl:url Dic:nil Suc:^(NSDictionary *data, NSString *code, NSString *msg) {
        if ([code isEqual:@"0"]) {
            NSArray *info = [data valueForKey:@"info"];
            
            CGFloat X = weakSelf.videoList.count*_window_height;
            for (int i=0; i<info.count; i++) {
                UIImageView *imagevB = [[UIImageView alloc]initWithFrame:CGRectMake(0, X, _window_width, _window_height)];
                imagevB.userInteractionEnabled = YES;
                imagevB.backgroundColor = [UIColor blackColor];
                imagevB.contentMode = UIViewContentModeScaleAspectFill;
                imagevB.clipsToBounds = YES;
//                [weakSelf.backScrollView addSubview:imagevB];
                [weakSelf.imgArr addObject:imagevB];
                [imagevB sd_setImageWithURL:[NSURL URLWithString:[info[i] valueForKey:@"thumb"]]];
                //如果是首页并且是第一个视频
                if (i == 0 && weakSelf.isHome == YES) {
                    weakCurrentImgV = imagevB;
                    weakCurrentImgV.hidden = YES;
//                    weakPlayer.placeholderImage = weakCurrentImgV.image;
                }
                X+=_window_height;
            }
            [weakSelf.videoList addObjectsFromArray:info];
            if (weakSelf.isHome == YES) {
                weakSelf.isHome = NO;
//                [self releaseWMPlayer];
//                [self createWmplayer];
//                [self setData];
//                [self getVideo];
                
                _currentVideoIndex = 0;
                _scrollViewOffsetYOnStartDrag = -100;
                [self scrollViewDidEndScrolling];
                
            }
            weakSelf.backScrollView.contentSize = CGSizeMake(_window_width, _window_height*weakSelf.videoList.count);
        }
    } Fail:nil];
}


#pragma mark - set/get
- (UIButton *)goBackBtn{
    if (!_goBackBtn) {
        //左
        _goBackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _goBackBtn.frame = CGRectMake(10, 22+statusbarHeight, 40, 40);
        _goBackBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
        [_goBackBtn setImage:[UIImage imageNamed:@"white_back"] forState:0];
        [_goBackBtn addTarget:self action:@selector(clickLeftBtn) forControlEvents:UIControlEventTouchUpInside];
        
        //左shadow
        _goBackShadow = [UIButton buttonWithType:UIButtonTypeCustom];
        _goBackShadow.frame = CGRectMake(0, 0, 64, 64+statusbarHeight);
        [_goBackShadow addTarget:self action:@selector(clickLeftBtn) forControlEvents:UIControlEventTouchUpInside];
        _goBackShadow.backgroundColor = [UIColor clearColor];
    }
    return _goBackBtn;
}

-(UIScrollView *)backScrollView{
    if (!_backScrollView) {
        _backScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height)];
        _backScrollView.contentSize =  CGSizeMake(_window_width, _window_height*3);
        _backScrollView.userInteractionEnabled = YES;
        _backScrollView.pagingEnabled = YES;
        _backScrollView.showsVerticalScrollIndicator = NO;
        _backScrollView.showsHorizontalScrollIndicator =NO;
        _backScrollView.delegate = self;
        _backScrollView.scrollsToTop = NO;
//        if (_videoList.count>0) {
//            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0) {
//                [_backScrollView setContentOffset:CGPointMake(0,_window_height*self.curentIndex+20) animated:YES];
//            }else{
//                [_backScrollView setContentOffset:CGPointMake(0,_window_height*self.curentIndex) animated:YES];
//            }
//        }
        _backScrollView.backgroundColor = [UIColor clearColor];
        
        _firstImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height)];
        _firstImageView.image = [UIImage imageNamed:@""];
        _firstImageView.contentMode = UIViewContentModeScaleAspectFill;
        _firstImageView.clipsToBounds = YES;
        [_backScrollView addSubview:_firstImageView];
        
        _secondImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, _window_height, _window_width, _window_height)];
        _secondImageView.image = [UIImage imageNamed:@""];
        _secondImageView.contentMode = UIViewContentModeScaleAspectFill;
        _secondImageView.clipsToBounds = YES;
        [_backScrollView addSubview:_secondImageView];
        _secondImageView.jp_videoPlayerDelegate = self;
        
        _thirdImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, _window_height*2, _window_width, _window_height)];
        _thirdImageView.image = [UIImage imageNamed:@""];
        _thirdImageView.contentMode = UIViewContentModeScaleAspectFill;
        _thirdImageView.clipsToBounds = YES;
        [_backScrollView addSubview:_thirdImageView];
        
        _firstFront = [[FrontView alloc]initWithFrame:_firstImageView.frame callBackEvent:^(NSString *type) {
            
        }];
        [_backScrollView addSubview:_firstFront];
        
        _secondFront = [[FrontView alloc]initWithFrame:_secondImageView.frame callBackEvent:^(NSString *type) {
            
        }];
        [_backScrollView addSubview:_secondFront];
        
        _thirdFront = [[FrontView alloc]initWithFrame:_thirdImageView.frame callBackEvent:^(NSString *type) {
            
        }];
        [_backScrollView addSubview:_thirdFront];
        
        
        
    }
    
    return _backScrollView;
}



#pragma mark - ============== 播放器代理
#pragma mark - JPVideoPlayerDelegate

- (BOOL)shouldShowBlackBackgroundBeforePlaybackStart {
    return NO;
}

-(void)playerStatusDidChanged:(JPVideoPlayerStatus)playerStatus {
    NSLog(@"=====7-8====%lu",(unsigned long)playerStatus);
}

#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView
                  willDecelerate:(BOOL)decelerate {
    if (decelerate == NO) {
        [self scrollViewDidEndScrolling];
    }
}

//- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
//    self.secondImageView.jp_progressView.hidden = NO;
//    [self scrollViewDidEndScrolling];
//}

//- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
//    self.secondImageView.jp_progressView.hidden = YES;
//    self.scrollViewOffsetYOnStartDrag = scrollView.contentOffset.y;
//}

- (NSURL *)fetchDouyinURL {
    if(self.currentVideoIndex == (self.douyinVideoStrings.count - 1)){
        self.currentVideoIndex = 0;
    }
    NSURL *url = [NSURL URLWithString:self.douyinVideoStrings[self.currentVideoIndex]];
    self.currentVideoIndex++;
    return url;
}

- (NSArray<NSString *> *)douyinVideoStrings {
    if(!_douyinVideoStrings){
        /*
         _douyinVideoStrings = @[
         @"http://www.w3school.com.cn/example/html5/mov_bbb.mp4",
         //@"https://www.w3schools.com/html/movie.mp4",
         @"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",
         @"https://media.w3.org/2010/05/sintel/trailer.mp4",
         @"http://mvvideo2.meitudata.com/576bc2fc91ef22121.mp4",
         @"http://mvvideo10.meitudata.com/5a92ee2fa975d9739_H264_3.mp4",
         @"http://mvvideo11.meitudata.com/5a44d13c362a23002_H264_11_5.mp4",
         @"http://mvvideo10.meitudata.com/572ff691113842657.mp4",
         @"https://api.tuwan.com/apps/Video/play?key=aHR0cHM6Ly92LnFxLmNvbS9pZnJhbWUvcGxheWVyLmh0bWw%2FdmlkPXUwNjk3MmtqNWV6JnRpbnk9MCZhdXRvPTA%3D&aid=381374",
         @"https://api.tuwan.com/apps/Video/play?key=aHR0cHM6Ly92LnFxLmNvbS9pZnJhbWUvcGxheWVyLmh0bWw%2FdmlkPWswNjk2enBud2xvJnRpbnk9MCZhdXRvPTA%3D&aid=381395",
         ];
         */
        _douyinVideoStrings = @[
                                @"http://qiniutxdemo.yunbaozhibo.com//video_12078_IOS_20180528093253.mp4",
                                @"http://qiniutxdemo.yunbaozhibo.com//video_12076_IOS_20180528092621.mp4",
                                @"http://qiniutxdemo.yunbaozhibo.com//video_12158_IOS_20180528092906.mp4",
                                @"http://qiniutxdemo.yunbaozhibo.com//video_12158_IOS_20180528093440.mp4",
                                @"http://qiniutxdemo.yunbaozhibo.com//video_12078_IOS_20180528093403.mp4",
                                @"http://qiniutxdemo.yunbaozhibo.com//video_12183_IOS_20180528094729.mp4",
                                @"http://qiniutxdemo.yunbaozhibo.com//video_12076_IOS_20180528091834.mp4",
                                @"http://qiniutxdemo.yunbaozhibo.com//video_12158_IOS_20180528093350.mp4",
                                @"http://qiniutxdemo.yunbaozhibo.com//video_12158_IOS_20180528095125.mp4",
                                @"http://qiniutxdemo.yunbaozhibo.com//video_12076_IOS_20180528092030.mp4"
                                ];
    }
    return _douyinVideoStrings;
}


@end
